﻿using UnityEngine;
using UnityEngine.UI;

public class PlayerController : MonoBehaviour {
	// === Unity ======================================================================================================
	public float speed;
	public Text countText;
	public Text winText;

	private void Start() {
		count = 0;
		SetCountText();
		winText.text = "";
	}

	private void FixedUpdate() {
		var moveHorizontal = Input.GetAxis("Horizontal");
		var moveVertical = Input.GetAxis("Vertical");

		var movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
		rigidbody.AddForce(movement * speed * Time.deltaTime);
	}

	private void OnTriggerEnter(Collider other) {
		if (other.gameObject.tag == "PickUp") {
			other.gameObject.SetActive(false);
			count += 1;
			SetCountText();
		}
//		Destroy(other.gameObject);
	}

	// === Private ====================================================================================================
	private int count;

	private void SetCountText() {
		countText.text = "Count: " + count;
		if (count >= 12) {
			winText.text = "YOU WIN!";
		}
	}
}
